<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 熊义 <34521664@qq.com> Date: 2025/3/10
// | 功能1：调用adminLogin钩子，在用户登陆时显示登陆页
// | 功能2：微信登陆，调用链接：https://f.kjdll.cn:9999/plugin/xiongyi/wechat/login
// +----------------------------------------------------------------------
namespace plugins\xiongyi;

use cmf\lib\Plugin;
use think\Db;

class XiongyiPlugin extends Plugin
{

    public $info = [
        'name'        => 'xiongyi',
        'title'       => 'xiongyi功能插件',
        'description' => 'xiongyi功能插件',
        'status'      => 1,
        'author'      => '熊义',
        'version'     => '1.0.0'
    ];

    public $hasAdmin = 0;//插件是否有后台管理界面

    //调用adminLogin钩子
    public function adminLogin()
    {
        $config=$this->getConfig();
        $this->assign('config',$config);
        return $this->fetch('widget');
    }

    // 插件安装
    public function install()
    {
        $thirdPartyLoginOption = cmf_get_option('third_party_login');
        if (empty($thirdPartyLoginOption)) {
            $thirdPartyLoginOption = [];
        }

        $thirdPartyLoginOption['WechatLogin'] = [
            'name'     => '微信',
            'key'      => 'wechat',
            'callback' => [
                'login'   => '',
                'binding' => ''
            ],
            'logo'     => 'plugins/xiongyi/images/wechat.png'
        ];

        cmf_set_option('third_party_login', $thirdPartyLoginOption, true);
        return true;//安装成功返回true，失败false
    }

    // 插件卸载
    public function uninstall()
    {
        $thirdPartyLoginOption = cmf_get_option('third_party_login');
        if (empty($thirdPartyLoginOption)) {
            $thirdPartyLoginOption = [];
        }

        unset($thirdPartyLoginOption['WechatLogin']);

        cmf_set_option('third_party_login', $thirdPartyLoginOption);
        return true;//卸载成功返回true，失败false
    }

}